function loadUserList(userRole,roleName) {
    hiddenSc(userRole);
    $.ajax({
        url:"/user/ajaxList",
        data:{"userRole":userRole,"roleName":roleName},
        type:"GET",
        success:function (htmlText) {
            $("#"+roleName).html(htmlText);
        }
    })

}

function hiddenSc(flag) {
    if (flag===0){
        $("#addUser").show()
        $("#scBtn").show();
        $("#scText").show();
    }else {
        $("#addUser").hide();
        $("#scBtn").hide();
        $("#scText").hide();
    }
}

function fuzzyUser() {
    $.ajax({
        url: "/user/fuzzyQueryUser",
        data: {"condition":$("#scText").val()},
        type: "GET",
        success:function (htmlText) {
            $("#allUser").html(htmlText)
        }
    })
}

function resetPassword(id){
    if (id==1){
        layer.open({
            icon:0,
            title: '提示',
            skin:'layui-layer-lan',
            anim:6,
            content: '管理员不可在此重置密码'
        });
        return;
    } else {
        layer.confirm('确定重置密码吗', {icon: 3, title:'提示'}, function(index){
            $.post({
                url:"/user/resetPassword",
                data:{"id":id},
                success:function (data) {
                    layer.msg(data.msg,{icon:1,shade:0.3,offset: '40%',time:2000,content:"重置成功"});
                    setTimeout(function(){
                        location.reload();
                    },1000);
                },
                error:function (data) {
                    layer.msg(data.msg,{icon:2,shade:0.3,offset: '40%',time:2000,content:"重置成功"});
                    setTimeout(function(){
                        location.reload();
                    },1000);
                }
            })
        })
    }

}

function userDetails(id) {
    layer.open({
        type:2,
        title: '查看',
        maxmin: true,
        skin: 'layui-layer-lan',
        shadeClose: true,
        area : ['400px' , '350px'],
        content:'/user/userDetails'+'?id='+id
    })
}

function userUpdate(id) {

    if (id==1){
        layer.open({
            icon:0,
            title: '提示',
            skin:'layui-layer-lan',
            anim:6,
            content: '管理员不可在此修改信息'
        });
        return;
    }

    layer.open({
        type:2,
        title: '修改',
        maxmin: true,
        skin: 'layui-layer-lan',
        shadeClose: true,
        area : ['600px' , '450px'],
        content:'/user/updateUser'+'?id='+id,
        end: function () {
            location.reload()
        }
    })
}

function addUser() {
    layer.open({
        type:2,
        title: '添加用户',
        maxmin: true,
        skin: 'layui-layer-lan',
        shadeClose: true,
        area : ['600px' , '450px'],
        content:'/user/addUser',
        end: function () {
            location.reload()
        }
    })
}

function deleteUser(id){
    if (id==1){
        layer.open({
            icon:0,
            title: '提示',
            skin:'layui-layer-lan',
            anim:6,
            content: '管理员不可删除'
        });
        return;
    } else {
        layer.confirm('确定删除吗', {icon: 3, title:'提示'}, function(index){
            $.post({
                url:"/user/deleteUser",
                data:{"id":id},
                success:function (data) {
                    var num = data.code==200 ? 1 : 2;
                    layer.msg(data.msg,{icon:num,shade:0.3,offset: '40%',time:2000,content:"正在删除"});
                    setTimeout(function(){
                        location.reload();
                    },1000);
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    if (jqXHR.status == 403){
                        layer.confirm('权限不足', {icon: 2, title:'提示'})
                    } else {
                        layer.confirm('发生错误', {icon: 2, title:'提示'})
                    }
                }
            })
        })
    }
}

function toRevisePassword() {

    layer.open({
        type:2,
        title: '修改密码',
        maxmin: true,
        skin: 'layui-layer-lan',
        shadeClose: true,
        area : ['300px' , '200px'],
        content:'/user/revisePassword',
        end: function () {
            location.reload()
        }
    })

}